package edu.sctu.jarime.june.day20150623.data;


import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user19 on 2015/6/24.
 */
public class JsonData {

    /**
     * 从接口获得json的文本 ，并转化为String
     * @param path
     * @return
     * @throws Exception
     */

    public static String getJson(String path) throws Exception {
        URL url = new URL(path);
        URLConnection connection = url.openConnection();
        connection.connect();
        InputStream inputStream = connection.getInputStream();

        byte[] buffer = new byte[1];
        String json="";

        while ((inputStream.read(buffer))!=-1){

           json=json+new String(buffer,0,buffer.length);

        }
        inputStream.close();

        return json;
    }
}
